<?php
class Admin_UserController extends Zend_Controller_Action 
{
	public function loginAction()
	{
		$service = new UserService();
		if ($this->getRequest()->isPost ()) {
			if($service->login())
			{
				$this->_redirect("/admin/product/index");exit;
			}
			else
			{
				$this->view->errorList = $service->getErrorMsg();
				$this->view->user = $_POST;
			}
		}
		
		$gui = $this->_helper->getHelper("Gui");
		$gui->hideMenu();
	}
	
	public function logoutAction()
	{
		$auth = Zend_Auth::getInstance();
		$auth->clearIdentity();
		$this->_redirect("/admin/user/login");exit;
	}
	
	public function indexAction()
	{
		$task = $this->_helper->getHelper("TaskList");
		
		$service = new UserService();
		$task->setService($service);
		
		$task->registerTask("search","userName");
		
		$data = $task->doTask();
		
		$gui = $this->_helper->getHelper("Gui");
		$gui->showData($data);
		$gui->setToolbar(array('new','edit','delete'),My_Translate::translate("USER_MANAGER"),"t_icon_user.png");
		
	}
	
	public function createAction()
	{	
		$service = new UserService();
		if ($this->getRequest()->isPost ()) {
			if($service->store())
			{
				$this->_redirect("/admin/user/index");exit;	
			}
			else
			{
				$this->view->errorList = $errorList;
				$this->view->user = $_POST;
			}
		}
		
		else
		{
			$id = $this->_getParam("id");
			$title = My_Translate::translate("USER_ADD");
			if(!empty($id))
			{
				$title = My_Translate::translate("USER_EDIT");
				$this->view->user = $service->loadData($id);
				$this->view->user['passconf'] = $this->view->user['password'];
			}
		}
		
		$gui = $this->_helper->getHelper("Gui");
		$gui->setToolbar(array('save','cancel'),$title,"t_icon_user.png");
		
	}
	
}
?>